/*
 * Copyright 2009 Al Phillips.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package xsd4gorm.xsd.parts

import xsd4gorm.model.DomainClass
import xsd4gorm.xsd.support.XSDPart
import xsd4gorm.xsd.support.XSDEdible
import xsd4gorm.xsd.support.XSDEdible
import xsd4gorm.xsd.support.XSDPart

/**
 *
 * @author Al Phillips
 */
public class ComplexType extends XSDPart implements XSDEdible {

    // Use this for anonymous classes 
    private String nameOverride

    public ComplexType(){
    }

    public ComplexType(String name){
        nameOverride = name
    }

    public void process(def node, def model){


        DomainClass gormClass = new DomainClass()
        
        if (nameOverride && nameOverride != ''){
            gormClass.setName(nameOverride)
        } else {
            gormClass.setName(node.@name.text())
        }
//        println 'complexType name = ' + gormClass.getName()
//        DomainClass gormClass = model.addGClass(node.@name)
        
        // sequence
        node.sequence.each {
            it.element.each {
                new Element().process(it, gormClass)
            }
        }

        // attribute
        node.attribute.each {
            // TODO: Can Attribute be treated the same as an Element for our purposes
            // new Attribute().process(it, gormClass)
            new Element().process(it, gormClass)
        }

        // all
        node.all.each {
            // TODO: all
        }

//        println 'end process ComplexType'
        model.addGClass(gormClass)
    }    

}